/*
 * Copyright 2006-2007 BearingPoint GDC
 *  
 *           file :     PasswordUtils.java
 *         project:     core
 *
 *     Create Date:     2006-11-18
 *          Author:     kevin.wang
 *
 *  [The change log]
 */

package com.mycompany.app.util.security;

import java.io.IOException;

import org.acegisecurity.providers.encoding.Md5PasswordEncoder;
import org.acegisecurity.providers.encoding.ShaPasswordEncoder;

/**
 * A helper class to help programmer or admin to generate a encrypted password
 * 
 * @author kevin.wang 2006-11-18
 */

public class PasswordUtils {
    public static void main(String[] args) throws IOException {

        // Display
        System.out.println("Please input Plain Text: ");

        // Read inputed data
        StringBuffer word = new StringBuffer("");
        int ch1;
        while ((ch1 = System.in.read()) != '\n') {
            word.append(ch1);
        }

        // Display
        System.out.println("Please input Salt Text: ");

        // Read inputed data
        StringBuffer salt = new StringBuffer("");
        int ch2;
        while ((ch2 = System.in.read()) != '\n') {
            salt.append(ch2);
        }

        // Initialize Password Encoder
        Md5PasswordEncoder md5encoder = new Md5PasswordEncoder();
        ShaPasswordEncoder shaencoder = new ShaPasswordEncoder();

        // Show the result
        System.out.println("MD5 encryped text :"
                + md5encoder.encodePassword(word.toString(), salt.toString()));
        System.out.println("SHA encryped text :"
                + shaencoder.encodePassword(word.toString(), salt.toString()));
    }

}
